package com.bioarktech.service;


import com.bioarktech.entity.Product;
import com.bioarktech.repository.ProductRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

@Service
public class ProductService {
    @Autowired
    private ProductRepository repo;

    public Page<Product> list(int page, int size) {
        return repo.findAll(PageRequest.of(page, size));
    }

    public Page<Product> listHomepage(int page, int size) {
        return repo.findByShowOnHomepageTrue(PageRequest.of(page, size));
    }

    public Product save(Product p) { return repo.save(p); }
    public Product get(Long id) { return repo.findById(id).orElseThrow(); }
}
